package com.mkx.multitier.request;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * 请求类，表示外部系统发送到请求接收层的请求
 */
public class Request {
    private final String requestId;
    private final String requestType;
    private final Map<String, Object> parameters;
    private final long timestamp;
    private final String source;
    
    public Request(String requestType, Map<String, Object> parameters, String source) {
        this.requestId = UUID.randomUUID().toString();
        this.requestType = requestType;
        this.parameters = parameters;
        this.timestamp = System.currentTimeMillis();
        this.source = source;
    }
    
    /**
     * 创建请求对象，接受JSON字符串作为内容
     */
    public Request(String requestType, String content, String source) {
        this.requestId = UUID.randomUUID().toString();
        this.requestType = requestType;
        this.parameters = new HashMap<>();
        this.parameters.put("content", content); // 存储JSON字符串内容
        this.timestamp = System.currentTimeMillis();
        this.source = source;
    }
    
    public String getRequestId() {
        return requestId;
    }
    
    public String getRequestType() {
        return requestType;
    }
    
    public Map<String, Object> getParameters() {
        return parameters;
    }
    
    public long getTimestamp() {
        return timestamp;
    }
    
    public String getSource() {
        return source;
    }
    
    @Override
    public String toString() {
        return "Request{" +
                "requestId='" + requestId + "'" +
                ", requestType='" + requestType + "'" +
                ", parameters=" + parameters +
                ", timestamp=" + timestamp +
                ", source='" + source + "'" +
                '}';
    }
}